package m2;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws MQClientException {
        //创建消费者
        DefaultMQPushConsumer c = new DefaultMQPushConsumer("c2");
        //设置 name server
        c.setNamesrvAddr("192.168.64.141:9876");
        //订阅消息
        c.subscribe("Topic2", "*");
        //设置单线程处理消息的监听器
        c.setMessageListener((MessageListenerOrderly) (msgs, context) -> {
            for (MessageExt ext : msgs) {
                String s = new String(ext.getBody());
                System.out.println("收到： "+s);
            }
            return ConsumeOrderlyStatus.SUCCESS;
            //return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
        });
        //启动
        c.start();
    }
}